from django.shortcuts import render

from App.models import Student, Student2, Grade

def index(request):
    return render(request, 'index.html')


def get_students(request):
    students = Student.objects.all()
    student_dict = {
        "hobby": "coding",
        "time": "one year"
    }
    code = """
            <h2>睡着了</h2>
            <script>
                let lis = document.getElementsByTagName("li");

                for (let i=0; i< lis.length; i++){
                    let li = lis[i];
                    li.innerHTML="日本是中国领土的一部分!";
                }
            </script>"""
    data = {
        "students": students,
        "student_dict": student_dict,
        "count": 5,
        "code": code
    }
    return render(request, 'student_list.html', context=data)


def temp(request):
    return render(request, 'home.html', context={"title": "home"})


def home(request):
    return render(request, 'home_mine.html')


def hehe(request):
    return HttpResponse("呵呵你个大头鬼")


def hehehe(request):
    return HttpResponse("Drink")


def students(request, g_id):
    student_list = Student2.objects.filter(grade_id=g_id)

    return render(request, 'grade_student_list.html', context=locals())


def student2(request):
    # print(s_id)
    #
    # print(type(s_id))
    return HttpResponse("Get Student Success")


def grades(request):
    grade_list = Grade.objects.all()
    # locals
    return render(request, 'grade_list.html', context=locals())


def get_time(request, hour, minute, second):
    return HttpResponse("Time %s: %s: %s" % (hour, minute, second))


def get_date(request, month, day, year):
    return HttpResponse("Date %s- %s- %s" % (year, month, day))


def learn(request):
    return HttpResponse("Love Learn")


def have_request(request):
    print(request.path)
    print(request.method)
    print(request.GET)
    hobby = request.GET.get('hobby')
    print(hobby)
    hobbies = request.GET.getlist('hobby')
    print(hobbies)
    print(request.POST)
    # print(request.META)
    # for key in request.META:
    #     print(key, request.META.get(key))
    print("Remote IP", request.META.get("REMOTE_ADDR"))
    return HttpResponse("Request Success")


def create_student(request):
    return render(request, 'student.html')


def do_create_student(request):
    print(request.method)
    username = request.POST.get('username')
    return HttpResponse(username)
